package com.yuliang.controller;

import com.yuliang.domain.R;
import com.yuliang.domain.dto.ArticleDto;
import com.yuliang.domain.vo.ArticleContentDetailVo;
import com.yuliang.service.ArticleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
@Api(tags = "文章")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public R writeArticle(@RequestBody ArticleDto articleDto){
        return articleService.writeArticle(articleDto);
    }

    @GetMapping("/list")
    public R getPageList(Integer pageNum,Integer pageSize,String title,String summary){
        return articleService.getPageList(pageNum,pageSize,title,summary);
    }

    @GetMapping("/{id}")
    public R getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleContentDetail(id);
    }

    @PutMapping
    public R updateArticle(@RequestBody ArticleContentDetailVo articleVo){
        return articleService.updateArticle(articleVo);
    }

    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable("id") Long id){
        return articleService.deleteById(id);
    }
}
